<template>
  <div class="app-container">
    <el-form
      ref="ruleForm"
      :model="ruleForm"
      :rules="rules"
      label-width="130px"
    >
      <el-form-item label="当前执行优惠方案">
        <el-input v-model="fangan" :disabled="true" style="width: 200px" />
      </el-form-item>
      <el-form-item label="优惠方案">
        <el-select
          v-model="ruleForm.discountSetting"
          placeholder="请选择优惠方案"
          clearable
          size="small"
          @change="discountSettingChang"
        >
          <el-option
            v-for="item in discountSettingOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          ></el-option>
        </el-select>
        <el-button size="mini" @click="save" type="primary"
          >确定执行该优惠方案</el-button
        >
      </el-form-item>
    </el-form>
    <el-form
      :model="zjParams"
      ref="zjParams"
      :inline="true"
      v-show="showZJ"
      label-width="68px"
    >
      <div>
        <span style="color: #ff9955; font-size: 25px">|</span
        ><span style="font-size: 25px">直降方案</span>
        <el-button
          icon="el-icon-plus"
          size="mini"
          @click="handleAddZJ"
          style="float: right"
          type="warning"
          v-hasPermi="['market:plan:add']"
          >添加直降信息</el-button
        >
      </div>
    </el-form>
    <el-table v-loading="loading" :data="ZJplanList" v-show="showZJ">
      <el-table-column label="id" align="left" prop="id" v-if="false" />
      <el-table-column label="方案名称" align="left" prop="grade" />
      <el-table-column label="油品名称" align="left" prop="oilName" />
      <el-table-column
        label="油品名称"
        align="left"
        prop="discountTerm"
        v-if="false"
        :formatter="discountTermFormat"
      />
      <el-table-column label="优惠条件" align="left" :formatter="planFormat" />
      <el-table-column
        label="优惠条件金额"
        v-if="false"
        align="left"
        prop="discountAmt"
      />
      <el-table-column
        label="优惠金额"
        v-if="false"
        align="left"
        prop="gasoilDiscountAmt"
      />
      <el-table-column
        label="等级优惠是否叠加"
        align="left"
        prop="vipDiscountyPlus"
        :formatter="vipDiscountyPlusFotmat"
      />
      <el-table-column
        label="可否叠加劵"
        align="left"
        prop="couponPlus"
        :formatter="couponPlusFotmat"
      />
      <el-table-column
        label="优惠方案类型"
        v-if="false"
        align="left"
        prop="discountPlanType"
      />
      <el-table-column
        label="操作"
        align="left"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope2">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateZJ(scope2.row)"
            v-hasPermi="['market:plan:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDeleteZJ(scope2.row)"
            v-hasPermi="['market:plan:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      :title="titlezj"
      :visible.sync="openzj"
      width="550px"
      append-to-body
    >
      <el-form
        ref="zjform"
        :model="zjform"
        :rules="zjrules"
        label-width="130px"
      >
        <el-form-item label="方案名称" prop="grade">
          <el-input v-model="zjform.grade" placeholder="请输入方案名称" />
        </el-form-item>
        <el-form-item label="油品名称" prop="oilName">
          <el-select
            v-model="zjform.oilName"
            placeholder="油品名称"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in oilNameOptionsZJ"
              :key="dict.oilName"
              :label="dict.oilName"
              :value="dict.oilName"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="优惠条件" prop="discountTerm">
          <el-radio-group v-model="zjform.discountTerm" @change="changeHandler">
            <el-radio
              v-for="dict in discountTermOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
          <div>
            满
            <el-input-number
              v-model="zjform.discountAmt"
              size="mini"
              :min="0"
            />
            <span v-show="laters">L</span>
            <span v-show="yuan">元</span>
            每升优惠
            <el-input-number
              v-model="zjform.gasoilDiscountAmt"
              size="mini"
              :min="0"
            />元
          </div>
        </el-form-item>
        <el-form-item label="等级优惠是否叠加" prop="vipDiscountyPlus">
          <el-radio-group v-model="zjform.vipDiscountyPlus">
            <el-radio
              v-for="dict in vipDiscountyPlusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
          <span style="margin-left: 20px; color: red"
            >注："否" 客户只享受直降优惠</span
          >
        </el-form-item>
        <el-form-item label="可否叠加劵" prop="couponPlus">
          <el-radio-group v-model="zjform.couponPlus">
            <el-radio
              v-for="dict in couponPlusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
          <span style="margin-left: 20px; color: red"
            >注："否" 客户只享受直降优惠</span
          >
        </el-form-item>
        <el-form-item
          v-show="false"
          label="优惠方案类型"
          prop="discountPlanType"
        >
          <el-select
            v-model="zjform.discountPlanType"
            placeholder="请选择优惠方案类型"
          >
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormZJ">确 定</el-button>
        <el-button @click="cancelZJ">取 消</el-button>
      </div>
    </el-dialog>
    <!--满减方案-->
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showMJ"
      label-width="68px"
    >
      <div>
        <span style="color: #ff9955; font-size: 25px">|</span
        ><span style="font-size: 25px">满减方案</span>
        <el-button
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          style="float: right"
          type="warning"
          v-hasPermi="['market:plan:add']"
          >添加满减信息</el-button
        >
      </div>
    </el-form>
    <el-table v-loading="loading" :data="planList" v-show="showMJ">
      <el-table-column label="id" align="left" prop="id" v-if="false" />
      <el-table-column label="方案名称" align="left" prop="grade" />
      <el-table-column label="油品名称" align="left" prop="oilName" />
      <el-table-column label="优惠条件" align="left">
        <template slot-scope="scope">
          每满 {{ scope.row.discountAmt }} 减 {{ scope.row.gasoilDiscountAmt }}
        </template>
      </el-table-column>
      <el-table-column
        label="优惠条件金额"
        v-if="false"
        align="left"
        prop="discountAmt"
      />
      <el-table-column
        label="优惠金额"
        v-if="false"
        align="left"
        prop="gasoilDiscountAmt"
      />
      <el-table-column
        label="等级优惠是否叠加"
        align="left"
        prop="vipDiscountyPlus"
        :formatter="vipDiscountyPlusFotmat"
      />
      <el-table-column
        label="可否叠加劵"
        align="left"
        prop="couponPlus"
        :formatter="couponPlusFotmat"
      />
      <el-table-column
        label="优惠方案类型"
        v-if="false"
        align="left"
        prop="discountPlanType"
      />
      <el-table-column
        label="操作"
        align="left"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['market:plan:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['market:plan:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加或修改满减 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="方案名称" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入等级名称" />
        </el-form-item>
        <el-form-item label="油品名称" prop="oilName">
          <el-select
            v-model="form.oilName"
            placeholder="油品名称"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in oilNameOptions"
              :key="dict.oilName"
              :label="dict.oilName"
              :value="dict.oilName"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="优惠条件" prop="discountTerm">
          每满
          <el-input-number v-model="form.discountAmt" size="mini" :min="0" />
          元 减
          <el-input-number
            v-model="form.gasoilDiscountAmt"
            size="mini"
            :min="0"
          />
          元
        </el-form-item>
        <el-form-item label="等级优惠是否叠加" prop="vipDiscountyPlus">
          <el-radio-group v-model="form.vipDiscountyPlus">
            <el-radio
              v-for="dict in vipDiscountyPlusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
          <span style="margin-left: 20px; color: red"
            >注："否" 客户只享受满减优惠</span
          >
        </el-form-item>
        <el-form-item label="可否叠加劵" prop="couponPlus">
          <el-radio-group v-model="form.couponPlus">
            <el-radio
              v-for="dict in couponPlusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
          <span style="margin-left: 20px; color: red"
            >注："否" 客户只享受满减优惠</span
          >
        </el-form-item>
        <el-form-item
          v-show="false"
          label="优惠方案类型"
          prop="discountPlanType"
        >
          <el-select
            v-model="form.discountPlanType"
            placeholder="请选择优惠方案类型"
          >
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--立减方案-->
    <el-form
      :model="selectParams"
      ref="selectFrom"
      :inline="true"
      v-show="showLJ"
      label-width="68px"
      style="margin-top: 25px"
    >
      <span style="color: #ff9955; font-size: 25px">|</span
      ><span style="font-size: 25px">立减方案</span>
      <el-button
        icon="el-icon-plus"
        size="mini"
        @click="handleAddDT"
        style="float: right"
        type="warning"
        v-hasPermi="['market:plan:add']"
        >添加立减方案</el-button
      >
    </el-form>
    <el-table v-loading="loading" :data="DTplanList" v-show="showLJ">
      <el-table-column label="id" align="left" prop="id" v-if="false" />
      <el-table-column label="方案名称" align="left" prop="grade" />
      <el-table-column label="油品名称" align="left" prop="oilName" />
      <el-table-column label="优惠条件" align="left">
        <template slot-scope="scope1">
          满 {{ scope1.row.discountAmt }} 减 {{ scope1.row.gasoilDiscountAmt }}
        </template>
      </el-table-column>
      <el-table-column
        label="优惠条件金额"
        v-if="false"
        align="left"
        prop="discountAmt"
      />
      <el-table-column
        label="优惠金额"
        v-if="false"
        align="left"
        prop="gasoilDiscountAmt"
      />
      <el-table-column
        label="等级优惠是否叠加"
        align="left"
        prop="vipDiscountyPlus"
        :formatter="vipDiscountyPlusFotmat"
      />
      <el-table-column
        label="可否叠加劵"
        align="left"
        prop="couponPlus"
        :formatter="couponPlusFotmat"
      />
      <el-table-column
        label="优惠方案类型"
        v-if="false"
        align="left"
        prop="discountPlanType"
      />
      <el-table-column
        label="操作"
        align="left"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope2">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateDT(scope2.row)"
            v-hasPermi="['market:plan:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDeleteDT(scope2.row)"
            v-hasPermi="['market:plan:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加或修改立减方案 -->
    <el-dialog
      :title="title"
      :visible.sync="opendt"
      width="550px"
      append-to-body
    >
      <el-form
        ref="dtform"
        :model="dtform"
        :rules="dtrules"
        label-width="130px"
      >
        <el-form-item label="方案名称" prop="grade">
          <el-input v-model="dtform.grade" placeholder="请输入等级名称" />
        </el-form-item>
        <el-form-item label="油品名称" prop="oilName">
          <el-select
            v-model="dtform.oilName"
            placeholder="油品名称"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in oilNameOptionsDT"
              :key="dict.oilName"
              :label="dict.oilName"
              :value="dict.oilName"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="优惠条件">
          满
          <el-input-number v-model="dtform.discountAmt" size="mini" :min="0" />
          元 减
          <el-input-number
            v-model="dtform.gasoilDiscountAmt"
            size="mini"
            :min="0"
          />
          元
        </el-form-item>
        <el-form-item label="等级优惠是否叠加" prop="vipDiscountyPlus">
          <el-radio-group v-model="dtform.vipDiscountyPlus">
            <el-radio
              v-for="dict in vipDiscountyPlusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
          <span style="margin-left: 20px; color: red"
            >注："否" 客户只享受立减优惠</span
          >
        </el-form-item>
        <el-form-item label="可否叠加劵" prop="couponPlus">
          <el-radio-group v-model="dtform.couponPlus">
            <el-radio
              v-for="dict in couponPlusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
          <span style="margin-left: 20px; color: red"
            >注："否" 客户只享受立减优惠</span
          >
        </el-form-item>
        <el-form-item
          label="优惠方案类型"
          v-show="false"
          prop="discountPlanType"
        >
          <el-select
            v-model="dtform.discountPlanType"
            placeholder="请选择优惠方案类型"
          >
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormDT">确 定</el-button>
        <el-button @click="cancelDT">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPlan,
  getPlan,
  delPlan,
  addPlan,
  updatePlan,
  exportPlan,
} from "@/api/market/plan";
import { getStationPay, updatePay } from "@/api/station/pay";
import { getDept } from "@/api/system/dept";
import { listPrice } from "@/api/station/price";
export default {
  name: "Setting",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户优惠等级设置表格数据
      planList: [],
      DTplanList: [],
      ZJplanList: [],
      couponPlusOptions: [],
      vipDiscountyPlusOptions: [],
      discountSettingOptions: [],
      stationOptions: [],
      oilNameOptions: [],
      oilNameOptionsDT: [],
      oilNameOptionsZJ: [],
      discountTermOptions: [],
      // 弹出层标题
      title: "",
      titlezj: "",
      fangan: "",
      // 是否显示弹出层
      open: false,
      yuan: true,
      laters: false,
      opendt: false,
      openzj: false,
      showZJ: false,
      showMJ: false,
      showLJ: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        grade: null,
        discountWay: null,
        gasoilDiscountLitre: null,
        dieseloilDiscountLitre: null,
        gradeType: null,
        gasoilConsume: null,
        gasoilGrowthValue: null,
        dieseloilConsume: null,
        dieseloilGrowthValue: null,
        growthValue: null,
        date: null,
        deductionGrowthValue: null,
      }, // 查询参数
      selectParams: {
        pageNum: 1,
        pageSize: 10,
        grade: null,
        discountWay: null,
        gasoilDiscountLitre: null,
        dieseloilDiscountLitre: null,
        gradeType: null,
        gasoilConsume: null,
        gasoilGrowthValue: null,
        dieseloilConsume: null,
        dieseloilGrowthValue: null,
        growthValue: null,
        date: null,
        deductionGrowthValue: null,
      },
      zjParams: {
        pageNum: 1,
        pageSize: 10,
        grade: null,
        discountWay: null,
        gasoilDiscountLitre: null,
        dieseloilDiscountLitre: null,
        gradeType: null,
        gasoilConsume: null,
        gasoilGrowthValue: null,
        dieseloilConsume: null,
        dieseloilGrowthValue: null,
        growthValue: null,
        date: null,
        deductionGrowthValue: null,
      },
      // 表单参数
      form: {},
      dtform: {},
      zjform: {},
      ruleForm: {
        imgFileList: [],
      },
      query: {
        deptId: null,
      },
      queryRule: {
        stationId: null,
      },
      // 表单校验
      rules: {},
      dtrules: {},
      zjrules: {
        discountTerm: [
          { required: true, message: "选择优惠执行规则", trigger: "blur" },
        ],
      },
      queryInfo: {
        stationId: null,
      },
      deptId: null,
      deptInfo: {},
    };
  },
  created() {
    this.getList();
    this.getList2();
    this.getList3();
    this.getDicts("coupon_plus").then((response) => {
      this.couponPlusOptions = response.data;
    });
    this.getDicts("discount_term").then((response) => {
      this.discountTermOptions = response.data;
    });
    this.getDicts("vip_discounty_plus").then((response) => {
      this.vipDiscountyPlusOptions = response.data;
    });
    //查看当前优惠设置
    this.queryRule.stationId = this.$store.selectDeptId;
    if (this.queryRule.stationId == null || this.queryRule.stationId == "") {
      this.queryRule.stationId = this.$store.state.user.deptId;
    }
    getStationPay(this.queryRule).then((response) => {
      this.ruleForm = response.data;
      let e = this.ruleForm.discountSetting;
      if (e == "1") {
        this.showZJ = false;
        this.showMJ = false;
        this.showLJ = false;
        this.fangan = "不执行优惠";
      } else if (e == "2") {
        this.showZJ = false;
        this.showMJ = true;
        this.showLJ = false;
        this.fangan = "满减";
      } else if (e == "3") {
        this.showZJ = false;
        this.showMJ = false;
        this.showLJ = true;
        this.fangan = "立减";
      } else if (e == "4") {
        this.showZJ = true;
        this.showMJ = false;
        this.showLJ = false;
        this.fangan = "直降";
      }
    });
    this.getDicts("discount_setting").then((response) => {
      this.discountSettingOptions = response.data;
    });
  },
  methods: {
    save() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          if (this.ruleForm.payId != null) {
            let e = this.ruleForm.discountSetting;
            if (e == "1") {
              updatePay(this.ruleForm).then((response) => {
                this.fangan = "不执行优惠";
                this.msgSuccess("优惠方案设置成功");
              });
            } else if (e == "2") {
              if (this.planList != null && this.planList.length > 0) {
                updatePay(this.ruleForm).then((response) => {
                  this.fangan = "满减";
                  this.msgSuccess("优惠方案设置成功");
                });
              } else {
                this.msgSuccess("满减规则下无方案");
              }
            } else if (e == "3") {
              if (this.DTplanList != null && this.DTplanList.length > 0) {
                updatePay(this.ruleForm).then((response) => {
                  this.fangan = "立减";
                  this.msgSuccess("优惠方案设置成功");
                });
              } else {
                this.msgSuccess("立减规则下无方案");
              }
            } else if (e == "4") {
              if (this.ZJplanList != null && this.ZJplanList.length > 0) {
                updatePay(this.ruleForm).then((response) => {
                  this.fangan = "直降";
                  this.msgSuccess("优惠方案设置成功");
                });
              } else {
                this.msgSuccess("直降规则下无方案");
              }
            }
          }
        }
      });
    },
    discountSettingChang(e) {
      if (e == "1") {
        this.showZJ = false;
        this.showMJ = false;
        this.showLJ = false;
      } else if (e == "2") {
        this.showZJ = false;
        this.showMJ = true;
        this.showLJ = false;
      } else if (e == "3") {
        this.showZJ = false;
        this.showMJ = false;
        this.showLJ = true;
      } else if (e == "4") {
        this.showZJ = true;
        this.showMJ = false;
        this.showLJ = false;
      }
    },
    changeHandler(value) {
      if (value == "2") {
        this.laters = false;
        this.yuan = true;
        this.zjform.discountTerm = "2";
      } else if (value == "1") {
        this.yuan = false;
        this.laters = true;
        this.zjform.discountTerm = "1";
      }
    },
    onInstitutionChang(e) {
      let obj = {};
      obj = this.stationOptions.find((item) => {
        //这里的userList就是上面遍历的数据源
        return item.stationId === e; //筛选出匹配数据
      });
      this.form.stationName = obj.deptName;
    },
    onInstitutionChang1(e) {
      let obj = {};
      obj = this.stationOptions.find((item) => {
        //这里的userList就是上面遍历的数据源
        return item.stationId === e; //筛选出匹配数据
      });
      this.dtform.stationName = obj.deptName;
    },
    /** 查询客户优惠等级设置列表 */
    getList() {
      this.queryParams.discountPlanType = "1";
      this.queryParams.stationId = this.$store.selectDeptId;
      if (
        this.queryParams.stationId == null ||
        this.queryParams.stationId == ""
      ) {
        this.queryParams.stationId = this.$store.state.user.deptId;
      }
      this.loading = true;
      listPlan(this.queryParams).then((response) => {
        this.planList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList2() {
      this.selectParams.discountPlanType = "2";
      this.selectParams.stationId = this.$store.selectDeptId;
      if (
        this.selectParams.stationId == null ||
        this.selectParams.stationId == ""
      ) {
        this.selectParams.stationId = this.$store.state.user.deptId;
      }
      this.loading = true;
      listPlan(this.selectParams).then((response) => {
        this.DTplanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList3() {
      this.zjParams.discountPlanType = "3";
      this.zjParams.stationId = this.$store.selectDeptId;
      if (this.zjParams.stationId == null || this.zjParams.stationId == "") {
        this.zjParams.stationId = this.$store.state.user.deptId;
      }
      this.loading = true;
      listPlan(this.zjParams).then((response) => {
        if (response.hasOwnProperty("rows")) {
          this.ZJplanList = response.rows;
        }
        this.loading = false;
      });
    },
    vipDiscountyPlusFotmat(row, column) {
      if (row.vipDiscountyPlus === "1") {
        return "是";
      } else if (row.vipDiscountyPlus === "2") {
        return "否";
      }
    },
    couponPlusFotmat(row, column) {
      if (row.couponPlus === "1") {
        return "是";
      } else if (row.couponPlus === "2") {
        return "否";
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancelDT() {
      this.opendt = false;
      this.reset();
    },
    // 取消按钮
    cancelZJ() {
      this.openzj = false;
      this.resetZJ();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        grade: null,
        discountWay: null,
        gasoilDiscountLitre: null,
        dieseloilDiscountLitre: null,
        gradeType: null,
        gasoilConsume: null,
        gasoilGrowthValue: null,
        dieseloilConsume: null,
        dieseloilGrowthValue: null,
        growthValue: null,
        date: null,
        stationId: null,
        stationName: null,
        deductionGrowthValue: null,
      };
      this.resetForm("form");
    },
    resetDT() {
      this.dtform = {
        id: null,
        grade: null,
        discountWay: null,
        gasoilDiscountLitre: null,
        dieseloilDiscountLitre: null,
        gradeType: null,
        gasoilConsume: null,
        gasoilGrowthValue: null,
        dieseloilConsume: null,
        dieseloilGrowthValue: null,
        growthValue: null,
        stationId: null,
        stationName: null,
        date: null,
        deductionGrowthValue: null,
      };
      this.resetForm("dtform");
    },
    resetZJ() {
      this.zjform = {
        id: null,
        grade: null,
        discountWay: null,
        gasoilDiscountLitre: null,
        dieseloilDiscountLitre: null,
        gradeType: null,
        gasoilConsume: null,
        gasoilGrowthValue: null,
        dieseloilConsume: null,
        dieseloilGrowthValue: null,
        growthValue: null,
        date: null,
        stationId: null,
        stationName: null,
        deductionGrowthValue: null,
      };
      this.resetForm("zjform");
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.deptId = this.$store.selectDeptId;
      if (this.deptId == null || this.deptId == "") {
        this.deptId = this.$store.state.user.deptId;
      }
      getDept(this.deptId).then((response) => {
        this.deptInfo = response.data;
        if (this.deptInfo.jiBie == 2) {
          this.open = true;
          this.title = "添加满减优惠";
          this.form.stationId = this.deptInfo.deptId;
          this.form.stationName = this.deptInfo.deptName;
          this.queryInfo.stationId = this.deptInfo.deptId;
          listPrice(this.queryInfo).then((response) => {
            this.oilNameOptions = response.rows;
          });
        } else {
          this.msgSuccess("请选择油站");
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPlan(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改满减优惠";
      });
    },
    /** 新增按钮操作 */
    handleAddDT() {
      this.resetDT();
      this.deptId = this.$store.selectDeptId;
      if (this.deptId == null || this.deptId == "") {
        this.deptId = this.$store.state.user.deptId;
      }
      getDept(this.deptId).then((response) => {
        this.deptInfo = response.data;
        if (this.deptInfo.jiBie == 2) {
          this.opendt = true;
          this.title = "添加立减优惠";
          this.dtform.stationId = this.deptInfo.deptId;
          this.dtform.stationName = this.deptInfo.deptName;
          this.queryInfo.stationId = this.deptInfo.deptId;
          listPrice(this.queryInfo).then((response) => {
            this.oilNameOptionsDT = response.rows;
          });
        } else {
          this.msgSuccess("请选择油站");
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdateDT(row) {
      this.resetDT();
      const id = row.id || this.ids;
      getPlan(id).then((response) => {
        this.dtform = response.data;
        this.opendt = true;
        this.title = "修改立减优惠";
      });
    },
    /** 新增按钮操作 */
    handleAddZJ() {
      this.resetZJ();
      this.deptId = this.$store.selectDeptId;
      if (this.deptId == null || this.deptId == "") {
        this.deptId = this.$store.state.user.deptId;
      }
      getDept(this.deptId).then((response) => {
        this.deptInfo = response.data;
        if (this.deptInfo.jiBie == 2) {
          this.openzj = true;
          //this.zjform.discountTerm="1";
          this.titlezj = "添加直降优惠";
          this.zjform.stationId = this.deptInfo.deptId;
          this.zjform.stationName = this.deptInfo.deptName;
          this.queryInfo.stationId = this.deptInfo.deptId;
          listPrice(this.queryInfo).then((response) => {
            this.oilNameOptionsZJ = response.rows;
          });
        } else {
          this.msgSuccess("请选择油站");
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdateZJ(row) {
      this.resetZJ();
      const id = row.id || this.ids;
      getPlan(id).then((response) => {
        this.zjform = response.data;
        this.openzj = true;
        this.titlezj = "修改直降优惠";
        if (this.zjform.discountTerm == "2") {
          this.yuan = true;
          this.laters = false;
        } else if (this.zjform.discountTerm == "1") {
          this.laters = true;
          this.yuan = false;
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.discountPlanType = "1";
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updatePlan(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlan(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitFormDT() {
      this.dtform.discountPlanType = "2";
      this.$refs["dtform"].validate((valid) => {
        if (valid) {
          if (this.dtform.id != null) {
            updatePlan(this.dtform).then((response) => {
              this.msgSuccess("修改成功");
              this.opendt = false;
              this.getList2();
            });
          } else {
            addPlan(this.dtform).then((response) => {
              this.msgSuccess("新增成功");
              this.opendt = false;
              this.getList2();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitFormZJ() {
      this.zjform.discountPlanType = "3";
      this.$refs["zjform"].validate((valid) => {
        if (valid) {
          if (this.zjform.id != null) {
            updatePlan(this.zjform).then((response) => {
              this.msgSuccess("修改成功");
              this.openzj = false;
              this.getList3();
            });
          } else {
            addPlan(this.zjform).then((response) => {
              this.msgSuccess("新增成功");
              this.openzj = false;
              this.getList3();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除满减优惠方案?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delPlan(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 删除按钮操作 */
    handleDeleteDT(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除立减优惠方案?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delPlan(ids);
        })
        .then(() => {
          this.getList2();
          this.msgSuccess("删除成功");
        });
    },
    /** 删除按钮操作 */
    handleDeleteZJ(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除直降优惠方案?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delPlan(ids);
        })
        .then(() => {
          this.getList3();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      if (queryParams.stationId == null || queryParams.stationId == "") {
        queryParams.stationId = this.$store.state.user.deptId;
      }
      this.$confirm("是否确认导出所有优惠设置数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportPlan(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    discountTermFormat(row, column) {
      if (row.discountTerm === "1") {
        return "按加油升数优惠";
      } else {
        return "按加油金额优惠";
      }
    },
    planFormat(row, column) {
      if (row.discountTerm === "1") {
        let ss =
          "满 " +
          row.discountAmt +
          "L,每升优惠 " +
          row.gasoilDiscountAmt +
          "元";
        return ss;
      } else {
        let ss =
          "满 " +
          row.discountAmt +
          "元,每升优惠 " +
          row.gasoilDiscountAmt +
          "元";
        return ss;
      }
    },
  },
};
</script>
<style></style>
